#!/bin/sh
# _cpptide_mac
clear
stop(){
	read -p "" -s -n 1
}
while true
do
	echo "欢迎使用cpptide 版本：1.23"
	echo "接下来要做什么？"
	echo "[1]创建/编辑一个项目"
        echo "[2]编译一个项目"
        echo "[3]运行一个项目"
        echo "[4]编译并运行一个项目"
	echo "[5]删除一个项目"
	echo "[6]重命名一个项目"
	echo "[7]将文件复制到一个项目"
	echo "[8]在一个项目中创建/编辑一个文件"
	echo "[9]更改编辑器设置"
	echo "[10]查看帮助"
	echo "[11]查看项目列表"
	echo "[12]查看项目内容"
	echo "[13]调试一个项目"
	echo "[14]编译并运行一个文件"
	echo "[15]在一个项目中创建一个文件夹"
	echo "[16]打开一个项目"
	echo "[17]运行一个命令"
	echo "[18]复制一个项目"
	echo "[19]粘贴一个项目"
	echo "[20]复制一个文件"
        echo "[21]粘贴一个文件"
	echo "[22]查看剪切板"
	echo "[23]查看主项目内容"
	echo "[24]查看项目文件内容"
	echo "[25]优化编译一个项目"
	echo "[26]生成项目预处理文件"
	echo "[27]生成项目汇编文件"
	echo "[28]生成项目目标文件"
	echo "[29]查看二进制文件"
	echo "[30]以树状查看所有项目"
	echo "[31]以树状查看一个项目"
	echo "[32]以彩色查看项目列表"
        echo "[33]以彩色查看项目内容"
	echo "[34]使用已有项目初始化一个项目"
	echo "[35]统计所有项目代码行数"
	echo "[36]使用一个文件初始化一个项目"
	echo "[37]访问一个网页"
	echo "[38]删除一个项目中的文件/文件夹"
	echo "[39]清除所有项目中可执行文件"
	echo "[40]清除一个项目中可执行文件"
        echo "[41]统计一个项目代码行数"
	echo "[42]查看所有项目大小"
	echo "[43]查看一个项目大小"
	echo "[44]查询一个函数用法"
	echo "[45]以指定标准编译一个项目"
	echo "[46]使用一个文件夹初始化一个项目"
	echo "[47]退出cpptide"
	read -p "请输入选项：" CHOOSE
	if [ "$CHOOSE" == "1" ]; then
		read -p "请输入项目名：" PROJECT1
		./edit "$PROJECT1"
		clear
	elif [ "$CHOOSE" == "2" ]; then
		read -p "请输入项目名：" PROJECT2
		g++ -o "./project/$PROJECT2/$PROJECT2" "./project/$PROJECT2/$PROJECT2.cpp"
		clear
        elif [ "$CHOOSE" == "3" ]; then
                read -p "请输入项目名：" PROJECT3
		clear
		"./project/$PROJECT3/$PROJECT3"
		stop
		clear
        elif [ "$CHOOSE" == "4" ]; then
                read -p "请输入项目名：" PROJECT4
		./build_run "./project/$PROJECT4" "$PROJECT4.cpp"
		stop
		clear
        elif [ "$CHOOSE" == "5" ]; then
                read -p "请输入项目名：" PROJECT5
		#rmdir ./project/$PROJECT5
		rm -rf "./project/$PROJECT5"
		clear
	elif [ "$CHOOSE" == "6" ]; then
		read -p "请输入旧项目名：" PROJECT61
		read -p "请输入新项目名：" PROJECT62
		mv "./project/$PROJECT61" "./project/$PROJECT62"
		mv "./project/$PROJECT62/$PROJECT61.cpp" "./project/$PROJECT62/$PROJECT62.cpp"
		clear
	elif [ "$CHOOSE" == "7" ]; then
		read -p "请输入项目名：" PROJECT71
		read -p "请输入文件位置：" PROJECT72
		read -p "请输入文件名：" PROJECT73
		mkdir -p "project/$PROJECT71"
		cp -f "$PROJECT72" "project/$PROJECT71/$PROJECT73"
		clear
	elif [ "$CHOOSE" == "8" ]; then
		read -p "请输入项目名：" PROJECT81
		read -p "请输入文件名：" PROJECT82
		vim "project/$PROJECT81/$PROJECT82"
		clear
        elif [ "$CHOOSE" == "9" ]; then
                vim ~/.vimrc
		clear
	elif [ "$CHOOSE" == "10" ]; then
		vim -R -m helpfile
		clear
	elif [ "$CHOOSE" == "11" ]; then
		ls project
		stop
		clear
	elif [ "$CHOOSE" == "12" ]; then
		read -p "请输入项目名：" PROJECT12
		ls "project/$PROJECT12"
		stop
		clear
	elif [ "$CHOOSE" == "13" ]; then
		read -p "请输入项目名：" PROJECT13
		g++ -g -o "./project/$PROJECT13/$PROJECT13" "./project/$PROJECT13/$PROJECT13.cpp"
		clear
		sudo gdb "./project/$PROJECT13/$PROJECT13"
		clear
	elif [ "$CHOOSE" == "14" ]; then
		read -p "请输入项目名：" PROJECT141
		read -p "请输入文件名：" PROJECT142
                ./build_run "./project/$PROJECT141" "$PROJECT142"
                clear
	elif [ "$CHOOSE" == "15" ]; then
		read -p "请输入项目名：" PROJECT151
		read -p "请输入文件夹名：" PROJECT152
		mkdir -p "project/$PROJECT151/$PROJECT152"
		clear
	elif [ "$CHOOSE" == "16" ]; then
		read -p "请输入项目名：" PROJECT16
		open "project/$PROJECT16"
		clear
	elif [ "$CHOOSE" == "17" ]; then
		read -p "请输入命令：" PROJECT17
		clear
		eval "$PROJECT17"
		stop
		clear
	elif [ "$CHOOSE" == "18" ]; then
		read -p "请输入项目名：" PROJECT18
		pbcopy < "project/$PROJECT18/$PROJECT18.cpp"
		clear
	elif [ "$CHOOSE" == "19" ]; then
                read -p "请输入项目名：" PROJECT19
                mkdir -p project/$PROJECT19
		pbpaste > "project/$PROJECT19/$PROJECT19.cpp"
                clear
	elif [ "$CHOOSE" == "20" ]; then
                read -p "请输入项目名：" PROJECT201
		read -p "请输入文件名：" PROJECT202
                pbcopy < "project/$PROJECT201/$PROJECT202"
                clear
        elif [ "$CHOOSE" == "21" ]; then
                read -p "请输入项目名：" PROJECT211
		read -p "请输入文件名：" PROJECT212
                mkdir -p "project/$PROJECT211"
		#touch project/$PROJECT211/$PROJECT212
                pbpaste > "project/$PROJECT211/$PROJECT212"
                clear
	elif [ "$CHOOSE" == "22" ]; then
		clear
		pbpaste
		stop
		clear
	elif [ "$CHOOSE" == "23" ]; then
		read -p "请输入项目名：" PROJECT23
		clear
		less "project/$PROJECT23/$PROJECT23.cpp"
		clear
	elif [ "$CHOOSE" == "24" ]; then
		read -p "请输入项目名：" PROJECT241
		read -p "请输入文件名：" PROJECT242
                clear
                less "project/$PROJECT241/$PROJECT242"
                clear
	elif [ "$CHOOSE" == "25" ]; then
		read -p "请输入项目名：" PROJECT251
		read -p "请输入优化等级：" PROJECT252
		g++ -O$PROJECT252 -o "./project/$PROJECT251/$PROJECT251" "./project/$PROJECT251/$PROJECT251.cpp"
		clear
	elif [ "$CHOOSE" == "26" ]; then
		read -p "请输入项目名：" PROJECT26
		g++ -E -o "./project/$PROJECT26/$PROJECT26.i" "./project/$PROJECT26/$PROJECT26.cpp"
		clear
	elif [ "$CHOOSE" == "27" ]; then
		read -p "请输入项目名：" PROJECT27
		g++ -S -o "./project/$PROJECT27/$PROJECT27.s" "./project/$PROJECT27/$PROJECT27.cpp"
		clear
	elif [ "$CHOOSE" == "28" ]; then
		read -p "请输入项目名：" PROJECT28
		g++ -c -o "./project/$PROJECT28/$PROJECT28.o" "./project/$PROJECT28/$PROJECT28.cpp"
		clear
	elif [ "$CHOOSE" == "29" ]; then
		read -p "请输入项目名：" PROJECT291
                read -p "请输入文件名：" PROJECT292
		clear
		xxd "project/$PROJECT291/$PROJECT292"
		stop
		clear
	elif [ "$CHOOSE" == "30" ]; then
		clear
		tree project
		stop
		clear
	elif [ "$CHOOSE" == "31" ]; then
		read -p "请输入项目名：" PROJECT31
		clear
                tree "project/$PROJECT31"
                stop
                clear
	elif [ "$CHOOSE" == "32" ]; then
                ls -G project
                stop
                clear
        elif [ "$CHOOSE" == "33" ]; then
                read -p "请输入项目名：" PROJECT33
                ls -G "project/$PROJECT33"
                stop
                clear
	elif [ "$CHOOSE" == "34" ]; then
		read -p "请输入已有项目名：" PROJECT341
		read -p "请输入初始化项目名：" PROJECT342
		cp -r "project/$PROJECT341" "project/$PROJECT342"
		mv "project/$PROJECT342/$PROJECT341.cpp" "project/$PROJECT342/$PROJECT342.cpp"
		clear
	elif [ "$CHOOSE" == "35" ]; then
		cloc project/*/*.cpp project/*/*.h
		stop
		clear
	elif [ "$CHOOSE" == "36" ]; then
		read -p "请输入项目名：" PROJECT361
                read -p "请输入文件位置：" PROJECT362
                mkdir -p "project/$PROJECT361"
                cp -f "$PROJECT362" "project/$PROJECT361/$PROJECT361.cpp"
                clear
	elif [ "$CHOOSE" == "37" ]; then
		read -p "请输入网址：" PROJECT37
		w3m "$PROJECT37"
		clear
	elif [ "$CHOOSE" == "38" ]; then
		read -p "请输入项目名：" PROJECT381
		read -p "请输入文件（夹）名：" PROJECT382
		rm -rf "project/$PROJECT381/$PROJECT382"
		clear
	elif [ "$CHOOSE" == "39" ]; then
		rm -f project/*/a.out
		clear
	elif [ "$CHOOSE" == "40" ]; then
		read -p "请输入项目名：" PROJECT40
		rm -f "project/$PROJECT40/a.out" "project/$PROJECT40/$PROJECT40"
		clear
	elif [ "$CHOOSE" == "41" ]; then
		read -p "请输入项目名：" PROJECT41
		cloc project/"$PROJECT41"/*.cpp project/"$PROJECT41"/*.h
		stop
		clear
	elif [ "$CHOOSE" == "42" ]; then
		clear
		du -d 0 -c -h project/*
		stop
		clear
	elif [ "$CHOOSE" == "43" ]; then
		read -p "请输入项目名：" PROJECT43
		clear
		du -a -c -h project/"$PROJECT43"/*
		stop
		clear
	elif [ "$CHOOSE" == "44" ]; then
		read -p "请输入函数名：" PROJECT44
		cppman "$PROJECT44"
		clear
	elif [ "$CHOOSE" == "45" ]; then
		read -p "请输入项目名：" PROJECT451
		read -p "请输入标准：" PROJECT452
		#g++ -std=c++$PROJECT452 -o "./project/$PROJECT451/$PROJECT451" "./project/$PROJECT451/$PROJECT451.cpp"
		g++ -std=$PROJECT452 -o "./project/$PROJECT451/$PROJECT451" "./project/$PROJECT451/$PROJECT451.cpp"
                clear
	elif [ "$CHOOSE" == "46" ]; then
		read -p "请输入项目名：" PROJECT361
                read -p "请输入文件夹位置：" PROJECT362
                mkdir project
                cp -rf "$PROJECT362" "project/$PROJECT361"
                clear
	elif [ "$CHOOSE" == "47" ]; then
		read -p "你确定要退出吗？" EXIT
		if [[ "$EXIT" == "y" || "$EXIT" == "Y" ]]; then
			clear
			exit
		elif [[ "$EXIT" == "n" || "$EXIT" == "N" ]]; then
			clear
		else
			clear
		fi
	else
		clear
	fi
done
